using System;
using System.Collections;
using System.Collections.Generic;

namespace CfgTable
{
    public partial class IntFloatKvList : IEnumerable<KeyValuePair<int, float>>
    {
        #region GetEnumerator

        public Enumerator GetEnumerator()
        {
            return new Enumerator(this);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return new Enumerator(this);
        }

        IEnumerator<KeyValuePair<int, float>> IEnumerable<KeyValuePair<int, float>>.GetEnumerator()
        {
            return new Enumerator(this);
        }

        [Serializable]
        public struct Enumerator : IEnumerator<KeyValuePair<int, float>>, IDisposable, IEnumerator
        {
            private int _index;
            private readonly int _count;
            private readonly IReadOnlyList<int> _keyArray;
            private readonly IReadOnlyList<float> _valueArray;

            private KeyValuePair<int, float> current;
            public KeyValuePair<int, float> Current => current;

            object System.Collections.IEnumerator.Current => Current;

            internal Enumerator(IntFloatKvList parent)
            {
                _keyArray = parent.key;
                _valueArray = parent.value;
                _index = -1;
                _count = _keyArray.Count;
                current = default(KeyValuePair<int, float>);
            }

            public bool MoveNext()
            {
                while (++_index < _count)
                {
                    current = new KeyValuePair<int, float>(_keyArray[_index], _valueArray[_index]);
                    return true;
                }

                return false;
            }

            public void Reset()
            {
                _index = -1;
                current = default(KeyValuePair<int, float>);
            }

            public void Dispose()
            {
            }
        }
        #endregion
    }
}
